package com.software.shipperagent.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import com.software.common.CommonUtils;
import com.software.form.bookingform.dao.BookingFormTransaction;

public class BookingFormServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		BookingFormTransaction bft = (BookingFormTransaction) CommonUtils.getBean("bookingFormTransaction");
		JSONObject json = CommonUtils.readJSONStringFromRequestBody(request, response);
		String email = (String) request.getSession().getAttribute("user");
		try{
			String shipper = json.getString("shipper");
			String con = json.getString("con");
			String np = json.getString("np");
			String por = json.getString("por");
			String pol = json.getString("pol");
			String ov = json.getString("ov");
			String podis = json.getString("podis");
			String podel = json.getString("podel");
			String mark = json.getString("mark");
			String quantity = json.getString("quantity");
			String cargo = json.getString("cargo");
			String weight = json.getString("weight");
			String m3 = json.getString("m3");
			String lae = json.getString("lae");
			boolean tag = false;
			tag = bft.add(con, weight, m3, mark, np, null, quantity, ov, podel, podis, pol, por, shipper, 0, cargo, lae, email);
			if(tag)
				CommonUtils.outputJsonData(1, response);
			else
				CommonUtils.outputJsonData(0, response);
		}catch(JSONException je){
			try {
				CommonUtils.outputJsonData(0, response);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
